package org.jeecg.modules.putstorage.controller;

import org.jeecg.modules.putstorage.entity.ZcglPutStorageAssets;
import org.jeecg.modules.zcgl.entity.AssetFixed;

import java.math.BigDecimal;


class Test {
    public static void main(String[] args) {
        AssetFixed assetFixed = new AssetFixed();
        assetFixed.setPrice(new BigDecimal("3.14"));
        assetFixed.setAmount(new BigDecimal("21"));

        ZcglPutStorageAssets zcglPutStorageAssets = new ZcglPutStorageAssets();
        zcglPutStorageAssets.setAssetPrice(new BigDecimal("1.5"));
        zcglPutStorageAssets.setAssetAmount(new BigDecimal("-20"));

        // 计算总的数量
        BigDecimal counts = assetFixed.getAmount().add(zcglPutStorageAssets.getAssetAmount());
        System.out.println("总的数量 counts: " + counts);

        // 计算总的金额
        BigDecimal total = assetFixed.getPrice().multiply(assetFixed.getAmount())
                .add(zcglPutStorageAssets.getAssetAmount().multiply(zcglPutStorageAssets.getAssetPrice()));
        System.out.println("总的金额 total: " + total);

        // 更新 assetFixed 的数量
        assetFixed.setAmount(assetFixed.getAmount().add(zcglPutStorageAssets.getAssetAmount()));

        // 计算平均价格
        BigDecimal price = BigDecimal.ZERO;
        if (counts.intValue() == 0) {
            price = BigDecimal.ZERO;
        } else {
            price = total.divide(counts, 2, BigDecimal.ROUND_HALF_UP);
        }
        System.out.println("平均价格 price: " + price);
    }
}

